﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AntikCompta.Data
{
    public class Produit
    {
        private String mReference;
        private String mNom;
        

        private DateTime mDateAchat;
        private float mPrixAchat;
        private Vendeur mVendeur;
        private ModePayement mAchatMode;
        private String mInfosVendeur;

        private DateTime mDateVente;
        private float mPrixVente;
        private Acheteur mAcheteur;
        private ModePayement mVenteMode;
        private String mFactureVente;

        public Produit() 
        {
            Init();
        }

        public Produit(String aReference)
        {
            mReference = aReference;
            Init();
        }

        private void Init()
        {
            mDateAchat = DateTime.MinValue;
            mPrixAchat=-1;
            mDateVente=DateTime.MinValue;
            mPrixVente=-1;

            mVendeur = new VendeurParticulier();
            mAcheteur = new AcheteurParticulier();

            mAchatMode = new Especes();
            mVenteMode = new Especes();
        }

        public float CalculTva(int aAnnee)
        {
            if (mAcheteur == null)
                return 0;

            // pas vendu
            if (mDateVente.Year != aAnnee)
                return 0;

            return mAcheteur.GetTva(mPrixAchat, mPrixVente);
        }

        static public String GetLotRef(String aRefPrduit)
        {
            String lotref = "";
            lotref = aRefPrduit.Substring(0, aRefPrduit.Length - 2);

            return lotref;
        }

        public String Reference
        {
            get { return mReference; }
            set { mReference = value; }
        }

        public String InfosVendeur
        {
            get { return mInfosVendeur; }
            set { mInfosVendeur = value; }
        }

        public String FactureVente
        {
            get { return mFactureVente; }
            set { mFactureVente = value; }
        }

        public String Nom
        {
            get { return mNom; }
            set { mNom = value; }
        }

        public DateTime DateAchat
        {
            get { return mDateAchat; }
            set { mDateAchat = value; }
        }

        public float PrixAchat
        {
            get { return mPrixAchat; }
            set { mPrixAchat = value; }
        }

        public DateTime DateVente
        {
            get { return mDateVente; }
            set { mDateVente = value; }
        }

        public float PrixVente
        {
            get { return mPrixVente; }
            set { mPrixVente = value; }
        }

        public Vendeur Vendeur
        {
            get { return mVendeur; }
            set { mVendeur = value; }
        }

        public Acheteur Acheteur
        {
            get { return mAcheteur; }
            set { mAcheteur = value; }
        }

        public ModePayement ModePayementAchat
        {
            get { return mAchatMode; }
            set { mAchatMode = value; }
        }

        public ModePayement ModePayementVente
        {
            get { return mVenteMode; }
            set { mVenteMode = value; }
        }


        internal bool AnnulerVente()
        {
            mDateVente = DateTime.MinValue;
            mPrixVente = -1;

            mAcheteur = new AcheteurParticulier();
            mVenteMode = new Especes();

            return true;
        }

        internal float CalculPrixVente(int aAnnee)
        {
            if (DateVente.Year != aAnnee)
                return 0;

            return mPrixVente;
        }

        internal float CalculBenefice(int aAnnee)
        {
            if (DateVente.Year != aAnnee)
                return 0;

            return mPrixVente - mPrixAchat - CalculTva(aAnnee);
        }
    }
}
